<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_CodeFunc.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:: do ::</title>
</head>
<body>
<!-- header start -->
<? include("../_layout/head.inc"); ?>
<!-- header end -->
<?
	$seq = $param->getNumber('seq');
	$seq2 = $param->getNumber('seq2');
	$mode = $param->getString('mode');
	$r_product_date = $param->getString('r_product_date');
	$r_product_grade1 = $param->getNumber('r_product_grade1');
	$r_product_grade2 = $param->getNumber('r_product_grade2');
	$r_product_standard1 = $param->getNumber('r_product_standard1');
	$r_product_standard2 = $param->getNumber('r_product_standard2');
	$r_product_weight1 = $param->getNumber('r_product_weight1');
	$r_product_weight2 = $param->getNumber('r_product_weight2');
	$r_product_number = $param->getNumber('r_product_number');
	$r_product_loss = $param->getNumber('r_product_loss');
	$r_product_total = $param->getNumber('r_product_total');
	$r_product_country = $param->getString('r_product_country');

	if ($mode == "w")
	{
		if ($seq=="" || $r_product_date=="" || $r_product_grade2=="" || $r_product_standard2=="" || $r_product_weight2=="" || $r_product_number=="" || $r_product_total=="")
		{
			jserror("입력값을 확인해주세요.","document.location='about:blank'");
			return;
		}
		$db = GetDefaultConnection();
		$sql = sprintf("SELECT JBNH_SEQ, FARM_SEQ, T_PRODUCT_ITEM1, T_PRODUCT_ITEM2 FROM TB_PRODUCT_TEMP a where T_PRODUCT_SEQ=%d", $seq);
		$list = $db->queryList($sql);
		if ($list != null)
		{
			$row = & $list->next();
			$_jseq = $row->getString('JBNH_SEQ');
			$_fseq = $row->getString('FARM_SEQ');
			$_item1 = $row->getString('T_PRODUCT_ITEM1');
			$_item2 = $row->getString('T_PRODUCT_ITEM2');
		}

		$article_arr = array(
			'T_PRODUCT_SEQ' => $seq,
			'R_PRODUCT_COUNTRY' => $r_product_country,
			'R_PRODUCT_GRADE1' => $r_product_grade1,
			'R_PRODUCT_GRADE2' => $r_product_grade2,
			'R_PRODUCT_STANDARD1' => $r_product_standard1,
			'R_PRODUCT_STANDARD2' => $r_product_standard2,
			'R_PRODUCT_WEIGHT1' => $r_product_weight1,
			'R_PRODUCT_WEIGHT2' => $r_product_weight2,
			'R_PRODUCT_NUMBER' => $r_product_number,
			'R_PRODUCT_LOSS' => $r_product_loss,
			'R_PRODUCT_TOTAL' => $r_product_total,
			"R_PRODUCT_DATE" => $r_product_date,
		);

		$no = ResultProduct_InsertArticle($article_arr);
		if ($no == -1)
		{
			jserror("등록중 오류가 발생했습니다.","document.location='about:blank'");
			return;
		}
		else
		{
			$totalnum = $r_product_number * $r_product_weight2;
			$article_arr2 = array(
				'PRODUCT_DATE' => $r_product_date,
				'T_PRODUCT_SEQ' => $seq,
				'JBNH_SEQ' => $_jseq,
				'FARM_SEQ' => $_fseq,
				'PRODUCT_COUNTRY' => $r_product_country,
				'PRODUCT_ITEM1' => $_item1,
				'PRODUCT_ITEM2' => $_item2,
				'PRODUCT_GRADE1' => $r_product_grade1,
				'PRODUCT_GRADE2' => $r_product_grade2,
				'PRODUCT_STANDARD1' => $r_product_standard1,
				'PRODUCT_STANDARD2' => $r_product_standard2,
				'PRODUCT_WEIGHT1' => $r_product_weight1,
				'PRODUCT_WEIGHT2' => $r_product_weight2,
				'PRODUCT_NUMBER' => $r_product_number,
				'PRODUCT_TOTAL' => $totalnum,
				'PRODUCT_TRADE' => 0,
			);
			$no = Product_InsertArticle($article_arr2);

			if ($no == -1)
			{
				jserror("등록중 오류가 발생했습니다.","document.location='about:blank'");
				return;
			}
			else
			{
				cacheControl(0);
				// 출력 버퍼를 비운다.
				ob_clean();
				jserror("등록되었습니다.","parent.location.reload()");
			}
		}

	}
	else if ($mode == "u")
	{
		if ($seq=="" || $seq2=="" || $r_product_date=="" || $r_product_grade2=="" || $r_product_standard2=="" || $r_product_weight2=="" || $r_product_number=="" || $r_product_total=="")
		{
			jserror("입력값을 확인해주세요.","document.location='about:blank'");
			return;
		}

		$article_arr = array(
			'T_PRODUCT_SEQ' => $seq,
			'R_PRODUCT_COUNTRY' => $r_product_country,
			'R_PRODUCT_GRADE1' => $r_product_grade1,
			'R_PRODUCT_GRADE2' => $r_product_grade2,
			'R_PRODUCT_STANDARD1' => $r_product_standard1,
			'R_PRODUCT_STANDARD2' => $r_product_standard2,
			'R_PRODUCT_WEIGHT1' => $r_product_weight1,
			'R_PRODUCT_WEIGHT2' => $r_product_weight2,
			'R_PRODUCT_NUMBER' => $r_product_number,
			'R_PRODUCT_LOSS' => $r_product_loss,
			'R_PRODUCT_TOTAL' => $r_product_total,
			"R_PRODUCT_DATE" => $r_product_date,
		);
		$no = ResultProduct_UpdateArticle($article_arr, $seq2);

		if ($no == -1)
		{
			jserror("수정중 오류가 발생했습니다.","document.location='about:blank'");
			return;
		}
		else
		{
			$totalnum = $r_product_number * $r_product_weight2;
			$article_arr2 = array(
				'PRODUCT_DATE' => $r_product_date,
				'PRODUCT_COUNTRY' => $r_product_country,
				'PRODUCT_GRADE1' => $r_product_grade1,
				'PRODUCT_GRADE2' => $r_product_grade2,
				'PRODUCT_STANDARD1' => $r_product_standard1,
				'PRODUCT_STANDARD2' => $r_product_standard2,
				'PRODUCT_WEIGHT1' => $r_product_weight1,
				'PRODUCT_WEIGHT2' => $r_product_weight2,
				'PRODUCT_NUMBER' => $r_product_number,
				'PRODUCT_TOTAL' => $totalnum,
			);
			$no = Product_UpdateArticle($article_arr2, $seq);
			if ($no == -1)
			{
				jserror("수정중 오류가 발생했습니다.","document.location='about:blank'");
				return;
			}
			else
			{
				cacheControl(0);
				// 출력 버퍼를 비운다.
				ob_clean();
				jserror("수정되었습니다.","parent.fnlist()");
			}
		}
	}
	else if ($mode == "d")
	{
		if ($seq=="" || $seq2=="")
		{
			jserror("입력값을 확인해주세요.","document.location='about:blank'");
			return;
		}
		$no = ResultProduct_DeleteArticle($seq, $seq2);
		if ($no == -1)
		{
			jserror("삭제중 오류가 발생했습니다.","document.location='about:blank'");
			return;
		}
		else
		{
			$no = Product_DeleteArticle($seq);
			if ($no == -1)
			{
				jserror("삭제중 오류가 발생했습니다.","document.location='about:blank'");
				return;
			}
			else
			{
				cacheControl(0);
				// 출력 버퍼를 비운다.
				ob_clean();
				jserror("삭제되었습니다.","parent.fnlist()");
			}
		}
	}
?>
</body>
</html>